<script src="<%- Virtual_Path.Static %>jquery.plugin/birthday/birthday.js"></script>
<link rel="stylesheet" href="<%- Virtual_Path.Static %>jquery.plugin/pagination/pagination.css">
<script src="<%- Virtual_Path.Static %>jquery.plugin/pagination/pagination.js"></script>
<div class="anchor-tab">
    <ul class="tab">
        <li class="on"><a href="/member/anchor">申请提现</a></li>
        <li><a href="/member/anchor/salary">基本工资</a></li>
        <li><a href="/member/anchor/live_data">直播数据</a></li>
        <li><a href="/member/anchor/gift_data">礼物数据</a></li>
    </ul>
</div>
<div class="anchor-cont">
    <div class="tabs-cont">
        <div class="hander-func">
            <p class="fl">查询时间：
                <select name="Birthday_Year" id="sel_year" rel=""></select>
                年
                <select name="Birthday_Month" id="sel_month" rel=""></select>
                月
                <select name="Ten_Day" id="sel_TenDay" rel="">
                    <option value="上旬" selected>上旬</option>
                    <option value="中旬">中旬</option>
                    <option value="下旬">下旬</option>
                </select>
                月
            </p>
            <a href="javascript:;" class="c-button fl" id="J_Anchor_Cash_Search">查询</a>
            <a href="javascript:;" class="c-button fr" OpenWindow=":AnchorCash:" id="J_Cash_Updates">提现</a>
            <p class="fr" style="margin-left: 20px;">金豆余额：<em class="c-orange" id="J_MyAnchor_Beans"></em></p>
            <p class="fr" style="margin-left: 20px;">本月任务收入：<em class="c-orange" id="J_MyAnchor_Task"></em></p>
            <p class="fr" style="margin-left: 20px;">活动收入：<em class="c-orange" id="J_MyAnchor_Not_Task"></em></p>

        </div>
        <div class="tableinfo">
            <table class="tabinfo">
                <thead>
                <tr>
                    <th>日期</th>
                    <th>提现收入(单位:元)</th>
                    <th>税点(50%)</th>
                    <th>实际收入(单位:元)</th>
                    <th>状态</th>
                </tr>
                </thead>
                <tbody id="J_OrderList">
                <tr>
                    <td colspan="5">加载中...</td>
                </tr>
                </tbody>
            </table>
        </div>
        <div id="AjaxPagination" class="pagination"></div>

        <div class="intro_tip">
            <h3>温馨提示：</h3>
            <p id="j_pulic_hint"></p>
            <p>◆.提现10天结算，只提现100的整数部分，分上中下三旬发放：</p>
            <p>◆.上旬1-10日的提现 ，11~13日打款到账</p>
            <p>◆.中旬11-20日的提现，21~23日打款到账</p>
            <p>◆.下旬21-月底的提现，次月1~3日打款到账</p>
            <p>◆.提现转账手续费由艺人承担，到账款项可能小于实际收入。</p>
            <p>◆.转账遇节假日延顺</p>
            <p>◆.每期只能提现一次</p>
        </div>
    </div>
</div>
<script>
    $(function () {
        $('#J_MyAnchor_Beans').empty().text(_PageData.Beans ? _PageData.Beans : 0);
        //临时方法
        $('#J_MyAnchor_Task').empty().text(_PageData.Beans_Anchor_Task ? _PageData.Beans_Anchor_Task : 0);
        $('#J_MyAnchor_Not_Task').empty().text((_PageData.Beans_Anchor_Task && _PageData.Beans_Anchor) ? (_PageData.Beans_Anchor - _PageData.Beans_Anchor_Task) : 0);
        //艺人所属公会为公对公，显示提示
        switch (_PageData.Settlement) {
            case 1:
                $('#j_pulic_hint').remove();
                break;
            case 2:
                $('#j_pulic_hint').empty().css({color: "red"}).text('◆.您所的公会与全民秀平台签署的公对公结算，您的收益将由全民秀网结算给您所在公会，请知晓，若有任何疑问请与全民秀网联系');
                break;
            default:
                $('#j_pulic_hint').remove();
                break;
        }

        if (!_StateData.IsLogin) {
            location.href = "/";
            return;
        }
        var _ThisPage = {
            PageParm: {
                P_Get: true,
                Loading: false, //加载中
                Total: null,       //总条数
                MaxCode: "",    //MaxCode
                Start: 0,       //开始
                Length: 10      //页长度
            }
        };
        var Create_Date = '';
        var Type = '';
        //时间搜索插件
        $.ms_DatePicker({
            YearSelector: ".sel_year",
            MonthSelector: ".sel_month",
        });
        $.ms_DatePicker();
        //搜索
        $('#J_Anchor_Cash_Search').on('click', function () {
            _ThisPage = {
                PageParm: {
                    P_Get: true,
                    Loading: false, //加载中
                    Total: null,       //总条数
                    MaxCode: "",    //MaxCode
                    Start: 0,       //开始
                    Length: 10      //页长度
                }
            };
            var param = {};
            param.year = $.trim($('#sel_year').val());
            param.month = $.trim($('#sel_month').val());
            param.tenday = $.trim($('#sel_TenDay').val());
            if (param.year == 0) {
                $.KOC.Tips.Open("Error", '请选择年份！', {Timeout: 2000});
                return;
            }
            if (param.month == 0) {
                $.KOC.Tips.Open("Error", '请选择月份！', {Timeout: 2000});
                return;
            }
            Create_Date = param.year + '-' + param.month;
            Type = param.tenday;
            AnchorData();
        });
        if (Create_Date == '') {
            AnchorData();
        }
        function AnchorData() {
            $.ajax({
                url: '/ajax/user.order-withdraw.page',
                type: 'post',
                dataType: 'json',
                data: {
                    P_Get: _ThisPage.PageParm.P_Get,
                    P_Total: _ThisPage.PageParm.Total,
                    P_MaxCode: _ThisPage.PageParm.MaxCode,
                    iDisplayStart: _ThisPage.PageParm.Start,
                    iDisplayLength: _ThisPage.PageParm.Length,
                    Sort_Col: "Create_Date",
                    Sort_Dir: "DESC",
                    Create_Date: Create_Date,
                    Type: Type
                },
                success: function (data) {
                    _ThisPage.PageParm.Loading = false;
                    _ThisPage.PageParm.P_Get = false;
                    if (data.flag !== 0) {
                        $.KOC.Tips.Open("Error", data.msg + "(" + data.flag + ")", {Timeout: 3000});
                        return;
                    }
                    _ThisPage.PageParm.Total = data.iTotalRecords;
                    if (data.iTotalRecords > 0) {
                        $("#AjaxPagination").empty().pagination(data.iTotalRecords, {
                            num_edge_entries: 2, //边缘页数
                            num_display_entries: 5, //主体页数
                            callback: PageCallback,
                            items_per_page: _ThisPage.PageParm.Length, //每页显示1项
                            prev_text: "前一页",
                            next_text: "后一页"
                        });
                    } else {
                        var _html = RenderPage(null, data.iTotalRecords);
                        $("#AjaxPagination").empty();
                        $('#J_OrderList').empty().html(_html);
                    }
                }
            })
        }

        function PageCallback(id) {
            _ThisPage.PageParm.Start = id * _ThisPage.PageParm.Length;
            InitTable(id);
        }

        function InitTable(index) {
            $.ajax({
                url: '/ajax/user.order-withdraw.page',
                type: 'post',
                dataType: 'json',
                data: {
                    P_Get: _ThisPage.PageParm.P_Get,
                    P_Total: _ThisPage.PageParm.Total,
                    P_MaxCode: _ThisPage.PageParm.MaxCode,
                    iDisplayStart: _ThisPage.PageParm.Start,
                    iDisplayLength: _ThisPage.PageParm.Length,
                    Sort_Col: "Create_Date",
                    Sort_Dir: "DESC",
                    Create_Date: Create_Date,
                    Type: Type
                },
                success: function (data) {
                    _ThisPage.PageParm.Loading = false;
                    _ThisPage.PageParm.P_Get = false;
                    if (data.flag !== 0) {
                        $.KOC.Tips.Open("Error", data.msg + "(" + data.flag + ")", {Timeout: 3000});
                        return;
                    }
                    _ThisPage.PageParm.Total = data.iTotalRecords;
                    _ThisPage.PageParm.MaxCode = data.sMaxCode;
                    _ThisPage.PageParm.Start += _ThisPage.PageParm.Length;
                    var _html = '';
                    if (_ThisPage.PageParm.Total > 0) {
                        _.forEach(data.aaData, function (ThisValue) {
                            _html += RenderPage(ThisValue);
                        });
                    }
                    $('#J_OrderList').empty().html(_html);
                }
            });
        }

        function RenderPage(ThisValue, len) {
            var _html = '';
            var status = '';
            var CreateTime = '';

            if (len <= 0) {
                _html += '<tr>' +
                        '<td colspan="5">' + '暂无数据！' +
                        '</td>' +
                        '</tr>';
            } else {
                if (parseInt(moment(ThisValue.Create_Date).format('DD')) >= 1 && parseInt(moment(ThisValue.Create_Date).format('DD')) <= 10) {
                    CreateTime = '上旬';
                } else if (parseInt(moment(ThisValue.Create_Date).format('DD')) >= 11 && parseInt(moment(ThisValue.Create_Date).format('DD')) <= 20) {
                    CreateTime = '中旬';
                } else {
                    CreateTime = '下旬';
                }
                (ThisValue.Status == 1) ? status = '结算中' : status = '已结算';
                _html += '<tr>' +
                        '<td>' + moment(ThisValue.Create_Date).format('YYYY-MM') + CreateTime +
                        '</td>' +
                        '<td>' + ThisValue.Money +
                        '</td>' +
                        '<td>' + ThisValue.Revenue_Money +
                        '</td>' +
                        '<td>' + ThisValue.Real_Money +
                        '</td>' +
                        '<td>' + status +
                        '</td>' +
                        '</tr>';
            }
            return _html;
        }
    })
</script>
